// DialogViewer.cpp : implementation file
//

#include "stdafx.h"
#include "testSVG.h"
#include "DialogViewer.h"
#include "webbrowser.h"
#include ".\dialogviewer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

char LastUrl[2000];

/////////////////////////////////////////////////////////////////////////////
// CDialogViewer dialog


CDialogViewer::CDialogViewer(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogViewer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogViewer)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDialogViewer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogViewer)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogViewer, CDialog)
	//{{AFX_MSG_MAP(CDialogViewer)
	ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
	ON_BN_CLICKED(IDC_BUTTON_HOME, OnButtonHome)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
	ON_WM_RBUTTONUP()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogViewer message handlers

BOOL CDialogViewer::OnInitDialog() 
{
	CDialog::OnInitDialog();

	CWebBrowser* viewer;
	

	viewer = (CWebBrowser*) GetDlgItem(IDC_EXPLORER1);

	if (!strcmp(fileName, ""))
	{
		strcpy(fileName, LastUrl);
	}

	viewer->Navigate(fileName, NULL, NULL, NULL, NULL);

	strcpy(LastUrl, fileName); 

	CButton* myButton;

	if (buttonsFlag)
	{
		
		myButton = (CButton*) GetDlgItem(IDC_BUTTON_BACK);
		myButton->EnableWindow(1);

		myButton = (CButton*) GetDlgItem(IDC_BUTTON_HOME);
		myButton->EnableWindow(1);
	}
	else
	{
		

		myButton = (CButton*) GetDlgItem(IDC_BUTTON_BACK);
		myButton->EnableWindow(1);

		myButton = (CButton*) GetDlgItem(IDC_BUTTON_HOME);
		myButton->EnableWindow(1);
	}
	m_back = 0;
	m_forward = 0;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogViewer::OnButtonBack() 
{
	CWebBrowser* viewer;
	CString location;
	CString temp;

	viewer = (CWebBrowser*) GetDlgItem(IDC_EXPLORER1);
	
	temp = fileName;
	if (viewer->GetLocationURL() != temp)
	{
		viewer->GoBack();
	}
	else
	{
		OnCancel();
	}
}

void CDialogViewer::OnButtonForward() 
{
	CWebBrowser* viewer;
	
	viewer = (CWebBrowser*) GetDlgItem(IDC_EXPLORER1);
	viewer->GoForward();
}

void CDialogViewer::OnButtonHome() 
{
	CWebBrowser* viewer;
	
	viewer = (CWebBrowser*) GetDlgItem(IDC_EXPLORER1);

	viewer->Navigate(fileName, NULL, NULL, NULL, NULL);;
	
}

void CDialogViewer::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	OnCancel();
}

void CDialogViewer::OnRButtonUp(UINT nFlags, CPoint point)
{
	CDialog::OnRButtonUp(nFlags, point);
}

BOOL CDialogViewer::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	return CDialog::OnWndMsg(message, wParam, lParam, pResult);
}

HRESULT CDialogViewer::accNavigate(long navDir, VARIANT varStart, VARIANT *pvarEndUpAt)
{
	return CDialog::accNavigate(navDir, varStart, pvarEndUpAt);
}

HRESULT CDialogViewer::accLocation(long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild)
{

	return CDialog::accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varChild);
}
